<template>
  <div>
    <BasicModal
      okText=""
      cancelText=""
      :minHeight="200"
      :maxHeight="500"
      :title="$t('table.member.member_remar_history')"
      @register="registerHistoryModal"
      :width="560"
      :titleIcon="props.titleicon"
      :woModalBtnGroups="true"
    >
      <BasicTable @register="registerTable" />
    </BasicModal>
  </div>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicTable, useTable, BasicColumn } from '/@/components/Table';
  import { getHistoryListNote } from '/@/api/member';
  import { typeShowOptions } from '../../../../common/const';
  import { toTimezone } from '/@/utils/dateUtil';
  import { useI18n } from '/@/hooks/web/useI18n';

  const { t } = useI18n();
  const props = defineProps<{
    titleicon: string;
  }>();
  const getUid = ref('' as string);
  const columns: BasicColumn[] = [
    {
      title: t('table.member.member_add_data'),
      dataIndex: 'created_at',
      minWidth: 100,
      customRender: ({ record }) => {
        return toTimezone(record.created_at, 'YYYY-MM-DD HH:mm:ss');
      },
    },
    {
      title: t('table.member.member_oprate_people'),
      dataIndex: 'created_by',
      minWidth: 100,
      customRender: ({ record }) => {
        return record.created_by ? record.created_by : '-';
      },
    },
    {
      title: t('table.member.member_oprate_event'),
      minWidth: 100,
      dataIndex: 'type',
      width: 120,
      customRender: ({ record }) => {
        //console.log(record.type);
        const arr: any = [];
        //return typeShowOptions[record.type];
        record?.type?.forEach((item) => {
          arr.push(typeShowOptions[item]);
        });
        return arr.length ? arr.join(',') : '-';
      },
    },
    {
      title: t('table.member.member_ramark_massage'),
      minWidth: 100,
      dataIndex: 'note',
    },
  ];
  const [registerHistoryModal] = useModalInner((data) => {
    getUid.value = data.uid;
  });
  const [registerTable] = useTable({
    api: getHistoryListNote,
    columns,
    bordered: true,
    maxHeight: 450,
    showIndexColumn: false,
    beforeFetch: (param) => {
      param['uid'] = getUid.value;
    },
  });
</script>
